<template>
	<view class="city">
		<view class="position">
			<view class="left">
				<view class="iconfont icon-dingwei"></view>
				自动定位：{{current_city}}
			</view>
			<view class="right" @click="goToChange">
				切换
				<view class="iconfont icon-qianjin"></view>
				<view></view>
			</view>
			
		</view>
		<view class="videolist">
			<view class="item" v-for="(item, index) in videolist" :key="index">
				<view class="video">
					<video
						:src="ip+'/video/'+item.src"
						:show-center-play-btn="false"
						:show-fullscreen-btn="false"
						></video>
				</view>
				<image class="img" src="../static/img/2-1.jpg" mode=""></image>
			</view>
		</view>
	</view>
</template>

<script>
	import t from '../common/helper.js';
	export default {
		name: "city",
		data() {
			return {
				ip: t.o,
				page: 0,
				current_city: '北京',
				videolist: '',
			};
		},
		props: ['currentpage'],
		watch: {
			//请求视频，只请求一次
			currentpage(val) {
				this.currentpage = val;
				if(this.videolist == '' && this.currentpage == 0) {
					this.getVideo();
				}
			}
		},
		methods: {
			getCurrentCity() {
				this.current_city = uni.getStorageSync('city') == '' ? '北京' : uni.getStorageSync('city');
			},
			getVideo() {
				uni.request({
					url: `${t.o}/videolist`,
					data: {
						line: 4,
					},
					success: res => {
						this.videolist = res.data.data;
					}
				})
			},
			//跳转到改变城市详情页，并且监听跳转后改变的城市
			goToChange() {
				let that = this;
				uni.navigateTo({
					url: '/pagesB/changecity/changecity',
					events: {
						changeCity() {
							that.getCurrentCity();
						}
					}
				})
			},
		},
		created() {
			this.getCurrentCity();
		}
	}
</script>

<style lang="scss">
	.city {
		box-sizing: border-box;
		height: 100%;
		width: 100%;
		background-color: #222222;
		padding-top: 85px;
		color: #797979;
		line-height: 25px;

		.position {
			display: flex;
			justify-content: space-between;
			padding: 0 20px;
			font-size: 14px;
			height: 30px;
			line-height: 30px;

			.left,
			.right {
				display: flex;
				align-items: center;

				.iconfont {
					color: #C0C0C0;
					font-size: 15px;
				}
			}

			.right {
				.iconfont {
					font-size: 8px;
					margin-left: 5px;
				}
			}
		}

		.videolist {
			margin-top: 10px;
			width: 100%;
			overflow: hidden;
			.item {
				float: left;
				width: 48%;
				margin: 3px 1%;
				position: relative;
				.video {
					width: 100%;
					height: 300px;
					// margin: 0 5%;
					video {
						width: 100%;
						height: 100%;
					}
				}

				.img {
					width: 30px;
					height: 30px;
					border-radius: 50%;
					position: absolute;
					bottom: 10px;
					left: 10px;
				}
			}
		}
	}
</style>
